//
//  RCTLatexView.m
//  latex_demo
//
//  Created by heaton on 2020/7/30.
//

#import "RCTLatexViewManager.h"
#import "CusMathLabel.h"
#import <React/RCTUIManagerObserverCoordinator.h>
#import <React/RCTUIManager.h>

@interface RCTLatexViewManager()<RCTUIManagerObserver>

@end

@implementation RCTLatexViewManager{
  LatexShadowView *_shadowView;
}

RCT_EXPORT_MODULE(RCTLatexView)

RCT_CUSTOM_SHADOW_PROPERTY(math, NSString, LatexShadowView){
//  view.latex = [RCTConvert NSString:json];
  [view setLatex:[RCTConvert NSString:json]];
}

- (void)setBridge:(RCTBridge *)bridge{
  [super setBridge:bridge];
  [bridge.uiManager.observerCoordinator addObserver:self];
}


-(UIView *)view{
  CusMathLabel *mathLabel = [[CusMathLabel alloc] init];
  mathLabel.labelMode = kMTMathUILabelModeText;
  mathLabel.backgroundColor = [UIColor redColor];
  mathLabel.fontSize = 16.0;
  mathLabel.displayErrorInline = NO;
  [mathLabel sizeToFit];
  return mathLabel;
}

- (RCTShadowView *)shadowView{
  LatexShadowView *shadowView = [[LatexShadowView alloc] initWithBridge:self.bridge];
  _shadowView = shadowView;
  return shadowView;
}

- (void)uiManagerWillPerformMounting:(RCTUIManager *)manager{
  [_shadowView uiManagerWillPerformMounting];
}
@end

